package org.agile2soft.nexoma.core.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
@Table(name="SERVICE", uniqueConstraints = { @UniqueConstraint(columnNames = {"SER_ID","SEG_ID"})} )
@SuppressWarnings({"serial"})
public class Service implements java.io.Serializable {

    private Integer id;
    private String  name;
    private String  comments;
    private boolean active;
    private boolean editable;
    private ServicesGroup group;
    private Set<ServiceOption> options = new HashSet<ServiceOption>(0);

    public Service(){
    }

    public Service(String name, boolean active, boolean editable, ServicesGroup group) {
        this.name = name;
        this.active = active;
        this.editable = editable;
        this.group=group;
    }

    public Service(String name, String comments,
            boolean active, boolean editable, ServicesGroup group) {
        this.name=name;
        this.comments = comments;
        this.active=active;
        this.editable=editable;
        this.group = group;
    }

    public Service(String name, boolean action,
                  String comments, boolean active, boolean editable,
                  String mode, ServicesGroup group,  Set<ServiceOption>options) {
        this.name=name;
        this.comments = comments;
        this.active=active;
        this.editable=editable;
        this.group = group;
        this.options=options;
    }

    @Id
    @GeneratedValue(strategy=IDENTITY)
    @Column(name="SER_ID", unique=true,nullable=false)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name="SER_NAME",unique=true,nullable=false,length=30)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    @Column(name="SER_COMMENTS",nullable=true,length=100)
    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    @Column(name="SER_ACTIVE",nullable=false)
    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    @Column(name="SER_EDITABLE",nullable=false)
    public boolean isEditable() {
        return editable;
    }

    public void setEditable(boolean editable) {
        this.editable = editable;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="SEG_ID",nullable=false,updatable=false)
    public ServicesGroup getGroup (){
        return this.group;
    }

    public void setGroup ( ServicesGroup group ) {
        this.group = group;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "service")
    public Set<ServiceOption> getOptions() {
        return this.options;
    }

    public void setOptions(Set<ServiceOption>options) {
        this.options=options;
    }


}
